from rest_framework import serializers

from MirrorCore.models.User import User


class UserSerializer(serializers.ModelSerializer):
    # id = serializers.IntegerField(source='self.id')
    is_staff = serializers.BooleanField(read_only=True)
    class Meta:
        model = User
        fields = ('id', 'nickname', 'photo', 'is_staff')


class AuthorByNameSerializer(serializers.ModelSerializer):

    def to_internal_value(self, data):
        return User.objects.get(name=data)

    def to_representation(self, instance):
        return instance.name
